package com.feijie.thread_demo.ThreadPool.controlller;

import com.feijie.thread_demo.ThreadPool.service.AsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @program: thread_demo
 * @description: 测试加入线程池
 * @author: 作者
 * @create: 2022-03-07 17:31
 */
@RestController
public class ThreadPoolController {

    @Autowired
    AsyncService asyncService;

/*    @Async
    @RequestMapping("test")
    public void test() throws InterruptedException {
        System.out.println("开始");
        System.out.println(Thread.currentThread().getName());
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int i = 1/0;
        System.out.println("结束");
    }*/

    @RequestMapping("/ticket1")
    public String ticket1() {
        asyncService.synMethod();
        return "success";
    }

    @RequestMapping("/ticket2/{ticketNo}")
    public String ticket2(@PathVariable("ticketNo") String ticketNo) {
        asyncService.synMethodByTicketNo(ticketNo);
        return "success";
    }

    @RequestMapping("/ticket3")
    public String ticket3() {
        asyncService.method();
        return "success";
    }

    @RequestMapping("/ticket4")
    public String ticket4() {
        asyncService.method();
        return "success";
    }

}
